package com.coda.controller;

import com.coda.entity.CityInfo;
import com.coda.entity.DistrictInfo;
import com.coda.entity.ProvinceInfo;
import com.coda.result.Result;
import com.coda.service.RegionInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/region")
@Api(tags = "地区信息管理")
public class RegionInfoController {
    @Autowired
    private RegionInfoService regionInfoService;

    /**
     * 查询省份信息列表
     */
    @GetMapping("/province/list")
    @ApiOperation(value = "查询省份信息列表")
    public Result<List<ProvinceInfo>> listProvince(){
        List<ProvinceInfo> provinceInfos = regionInfoService.getProvinceList();
        return Result.ok(provinceInfos);
    }
    /**
     * 根据省份id查询城市信息列表
     */
    @GetMapping("/city/listByProvinceId")
    @ApiOperation(value = "根据省份id查询城市信息列表")
    public Result<List<CityInfo>> listCity(Long id){
        List<CityInfo> cityInfos = regionInfoService.getCityList(id);
        return Result.ok(cityInfos);
    }
    /**
     * 根据城市id查询区县信息
     */
    @GetMapping("/district/listByCityId")
    @ApiOperation(value = "根据城市id查询区县信息")
    public Result<List<DistrictInfo>> getDistrict(Long id){
        List<DistrictInfo> districtInfos = regionInfoService.getDistrict(id);
        return Result.ok(districtInfos);
    }

}
